package com.iot.ic.service;



import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iot.ic.common.CustomException;
import com.iot.ic.common.ReturnCode;
import com.iot.ic.dao.EquipmentInfoMapper;
import com.iot.ic.dao.RefereeInfoMapper;
import com.iot.ic.dao.TeamInfoMapper;
import com.iot.ic.model.EquipmentInfo;
import com.iot.ic.model.MatchScenesInfo;
import com.iot.ic.model.RefereeInfo;
import com.iot.ic.model.TeamInfo;

/**
 * 
 */
@Service
public class EquipmentServiceImpl implements EquipmentService {

	@Autowired
	private EquipmentInfoMapper equipmentInfoMapper;
	
	@Autowired
	private MatchScenesService matchScenesService;


	@Override
	public List<EquipmentInfo> listEquipmentInfosByScenes(Integer scenesId) {
		List<EquipmentInfo> resultList = equipmentInfoMapper.listEquipmentInfosByScenes(scenesId);
		return resultList;
	}

	@Override
	public int deleteEquipmentInfo(Integer equipmentId) {
		EquipmentInfo equipmentInfo = equipmentInfoMapper.selectByPrimaryKey(equipmentId);
		int result = equipmentInfoMapper.deleteEquipmentInfo(equipmentId);
		//修改场景违规数量
		if (result > 0){
			MatchScenesInfo matchScenesInfo = matchScenesService.getMatchScenesById(equipmentInfo.getScenesId());
			int oldIllegalCount = matchScenesInfo.getEquipmentCount();
			matchScenesInfo.setEquipmentCount(oldIllegalCount -1);
			result = matchScenesService.updateMatchScenes(matchScenesInfo);
		}
		return result;
	}

	@Override
	public int addEquipmentInfo(EquipmentInfo equipmentInfo) {
		int result = equipmentInfoMapper.insert(equipmentInfo);
		//修改场景违规数量
		if (result > 0){
			MatchScenesInfo matchScenesInfo = matchScenesService.getMatchScenesById(equipmentInfo.getScenesId());
			int oldIllegalCount = matchScenesInfo.getEquipmentCount();
			matchScenesInfo.setEquipmentCount(oldIllegalCount +1);
			result = matchScenesService.updateMatchScenes(matchScenesInfo);
		}
		return result;
	}

	@Override
	public EquipmentInfo getEquipmentInfoById(Integer equipmentId) {
		EquipmentInfo equipmentInfo = equipmentInfoMapper.selectByPrimaryKey(equipmentId);
		
		return equipmentInfo;
	}

	@Override
	public int updateEquipmentInfo(EquipmentInfo equipmentInfo) {
		int result = equipmentInfoMapper.updateByPrimaryKeySelective(equipmentInfo);
		return result;
	}



	
	
	
	
	
	
}
